<template>
  <div v-if="show" class="modal-overlay" @click.self="$emit('close')">
    <div class="modal-content modern-modal" :style="{ maxWidth: width }">
      <div class="modal-header" :style="headerStyle">
        <div class="header-title">
          <span class="header-icon">{{ icon }}</span>
          <h2>{{ title }}</h2>
        </div>
        <span class="close-btn" @click="$emit('close')">&times;</span>
      </div>
      <div class="modal-body">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  title: {
    type: String,
    required: true
  },
  show: {
    type: Boolean,
    default: false
  },
  icon: {
    type: String,
    default: '📝'
  },
  width: {
    type: String,
    default: '600px'
  },
  headerColor: {
    type: String,
    default: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
  }
})

defineEmits(['close'])

const headerStyle = computed(() => ({
  background: props.headerColor
}))
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  width: 90%;
  animation: modal-in 0.3s ease-out;
}

.modal-header {
  color: white;
  padding: 20px 30px;
  border-radius: 16px 16px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  font-size: 24px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.close-btn {
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  transition: opacity 0.2s;
}

.close-btn:hover {
  color: white;
}

.modal-body {
  padding: 30px;
  background: #f8f9fa;
  overflow-y: auto;
  flex: 1;
  border-radius: 0 0 16px 16px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
</style>
